package com.base.controller;

import com.base.po.voip.UsersRebate;
import com.base.service.RewardsService;
import com.base.service.SubscribersService;
import com.base.service.UsersRebateService;
import com.base.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 现在充值分销配置
 *
 */
@Controller
@RequestMapping("/admin")
public class UsersRebateIndexController {

	@Autowired
	private UsersService usersService; // 账户信息Service
	@Autowired
	private SubscribersService subscribersService;
	@Autowired
	private RewardsService rewardsService;
	@Autowired
	private UsersRebateService usersRebateService;

	// 账户配置主页
	@RequestMapping("/usersrebate_index")
	public ModelAndView index(HttpServletRequest request, HttpSession session, Integer type) {
		// 返回ModelAndView
		ModelAndView modelAndView = new ModelAndView();

		Object obj_id = session.getAttribute("adminUserId"); // 登录的用户ID
		if (obj_id == null) {
			modelAndView.setViewName("jsp/loginCheck");
			return modelAndView; // 未登录
		}

		UsersRebate usersRebate =  usersRebateService.selectByParentId((String)obj_id, type);
		if (usersRebate == null){
			// 未查询到 插入
			usersRebateService.insertSelective(new UsersRebate((String)obj_id, type));
			usersRebate =  usersRebateService.selectByParentId((String)obj_id, type);
		}

		request.setAttribute("usersRebate", usersRebate);
		request.setAttribute("type", type);
		modelAndView.setViewName("jsp/usersrebate_index");
		return modelAndView;
	}
}
